﻿using MediatR;
using S.EarTag.Domain.Dto;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IEarTagRepository;
using S.EarTag.Read.API.Application.MediatorCommand.BreedingWeighCommand;

namespace S.EarTag.Read.API.Application.MediatorCommandHandler.BreedingWeighCommandHandler
{
    public class BreedingWeighShowCommandHandler : IRequestHandler<BreedingWeighShowCommand, (IEnumerable<QueryResult> items, int totalCount, int pageCount)>
    {
        private readonly IBreedingWeighRepository db;
        public BreedingWeighShowCommandHandler(IBreedingWeighRepository db)
        {
            this.db = db;
        }
        
        public async Task<(IEnumerable<QueryResult> items, int totalCount, int pageCount)> Handle(BreedingWeighShowCommand request, CancellationToken cancellationToken)
        {
            var result =  await db.BreedingList(request.startDate, request.endDate, request.EarTag, request.WeighCategory, request.VarietyEnum, request.Sex, request.page, request.size);
            var items = result.items;
            var totalCount = result.totalCount;
            var pageCount = result.pageCount;
            return (items, totalCount, pageCount);
        }



    }
}
